import 'package:flutter/cupertino.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';

import 'hc_common_theme.dart';

class HcNoticeBarTheme extends HcBaseTheme<HcNoticeBarTheme> {
  //圆角
  double? _radius;

  //间隔
  double? _spacing;

  //文字大小
  double? _fontSize;

  double? _fontHeight;

  //文字宽度
  FontWeight? _fontWeight;

  //边距
  EdgeInsets? _padding;
  EdgeInsets? _leadingMargin;
  EdgeInsets? _trailingMargin;

  //默认Icon大小
  double? _leadingSize;
  double? _trailingSize;

  HcNoticeBarTheme({
    double? spacing,
    EdgeInsets? padding,
    EdgeInsets? leadingMargin,
    EdgeInsets? trailingMargin,
    double? leadingSize,
    double? trailingSize,
    double? fontSize,
    double? fontHeight,
    double? radius,
    FontWeight? fontWeight,
  })  : _spacing = spacing,
        _padding = padding,
        _leadingMargin = leadingMargin,
        _trailingMargin = trailingMargin,
        _radius = radius,
        _fontHeight = fontHeight,
        _leadingSize = leadingSize,
        _trailingSize = trailingSize,
        _fontSize = fontSize,
        _fontWeight = fontWeight;

  @override
  void initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    HcNoticeBarTheme noticeBarTheme =
        HcCustomerConfig().allTheme.noticeBarTheme;
    _spacing ??= commonTheme.hSpacingXs;
    _padding ??= EdgeInsets.symmetric(
        vertical: commonTheme.vSpacingSm, horizontal: commonTheme.hSpacingPage);
    _leadingMargin = EdgeInsets.only(right: commonTheme.hSpacingXs);
    _trailingMargin = EdgeInsets.only(left: commonTheme.hSpacingXs);
    _radius ??= noticeBarTheme.radius;
    _fontHeight ??= commonTheme.fontHeightLg;
    _leadingSize ??= commonTheme.iconSizeXxs;
    _trailingSize ??= commonTheme.iconSizeXxs;
    _fontSize ??= commonTheme.fontSizeBase;
    _fontWeight ??= noticeBarTheme.fontWeight;
  }

  @override
  HcNoticeBarTheme merge(HcNoticeBarTheme? value) {
    if (value == null) return this;
    return copyWith(
        spacing: value._spacing,
        padding: value._padding,
        radius: value._radius,
        leadingSize: value._leadingSize,
        trailingSize: value._trailingSize,
        fontSize: value._fontSize,
        fontHeight: value._fontHeight,
        fontWeight: value._fontWeight);
  }

  HcNoticeBarTheme copyWith({
    double? spacing,
    EdgeInsets? padding,
    double? radius,
    double? fontHeight,
    double? leadingSize,
    double? trailingSize,
    FontWeight? fontWeight,
    double? fontSize,
  }) {
    return HcNoticeBarTheme(
      spacing: spacing ?? _spacing,
      padding: padding ?? _padding,
      radius: radius ?? _radius,
      fontSize: fontSize ?? _fontSize,
      fontWeight: fontWeight ?? _fontWeight,
      fontHeight: fontHeight ?? _fontHeight,
      leadingSize: leadingSize ?? _leadingSize,
      trailingSize: trailingSize ?? _leadingSize,
    );
  }

  EdgeInsets get padding =>
      _padding ?? HcDefaultThemeConfig.defaultNoticeBarTheme.padding;

  double get spacing =>
      _spacing ?? HcDefaultThemeConfig.defaultNoticeBarTheme.spacing;

  double get leadingSize =>
      _leadingSize ?? HcDefaultThemeConfig.defaultNoticeBarTheme.leadingSize;

  double get trailingSize =>
      _trailingSize ?? HcDefaultThemeConfig.defaultNoticeBarTheme.trailingSize;

  FontWeight get fontWeight =>
      _fontWeight ?? HcDefaultThemeConfig.defaultNoticeBarTheme.fontWeight;

  double get fontSize =>
      _fontSize ?? HcDefaultThemeConfig.defaultNoticeBarTheme.fontSize;

  double get radius =>
      _radius ?? HcDefaultThemeConfig.defaultNoticeBarTheme.radius;

  double get fontHeight =>
      _fontHeight ?? HcDefaultThemeConfig.defaultNoticeBarTheme.fontHeight;

  EdgeInsets get trailingMargin => _trailingMargin?? HcDefaultThemeConfig.defaultNoticeBarTheme.trailingMargin;

  EdgeInsets get leadingMargin => _leadingMargin?? HcDefaultThemeConfig.defaultNoticeBarTheme.leadingMargin;
}
